package cn.gzjp.modules.dt.service;

import java.util.List;

import cn.gzjp.modules.dt.entity.QuestionOption;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.gzjp.common.persistence.Page;
import cn.gzjp.common.service.CrudService;
import cn.gzjp.modules.dt.entity.Question;
import cn.gzjp.modules.dt.dao.QuestionDao;

/**
 * 题目Service
 * @author zengcp
 * @version 2018-02-24
 */
@Service
@Transactional(readOnly = true)
public class QuestionService extends CrudService<QuestionDao, Question> {

	@Autowired
	private QuestionOptionService questionOptionService;

	public Question get(Integer id) {
		Question question =  dao.get(id);
		QuestionOption search = new QuestionOption();
		search.setQuestion(question);
		question.setOptions(questionOptionService.findList(search));
		return question;

	}
	
	public List<Question> findList(Question question) {
		return super.findList(question);
	}
	
	public Page<Question> findPage(Page<Question> page, Question question) {
		return super.findPage(page, question);
	}
	
	@Transactional(readOnly = false)
	public void save(Question question) {
		super.save(question);
	}
	
	@Transactional(readOnly = false)
	public void delete(Question question) {
		super.deleteByLogic(question);
	}

	public Integer getCount(){
		return dao.getCount();
	}
}